<admintpl file="header"/></head>
<body>
<div class="wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a>贷后核准列表</a></li>
    </ul>
    <form class="well form-search" method="post" action="{:U('afterloan/audit_list')}" style='line-height: 46px;'>
        <input type="text" name="mobile" placeholder="请输入手机号" value="{:I('request.mobile')}" />
        <input type="text" name="name" placeholder="请输入姓名" value="{:I('request.name')}" />
        <input type="text" name="principal" placeholder="登记人" value="{:I('request.principal')}" />
        <input type="text" name="operation_date" placeholder="登记时间" class="js-date" value="{:I('request.operation_date')}" />
        <select name="is_check">
            <option value="">核准状态</option>
            <option value="0">未核准</option>
            <option value="1">已核准</option>
        </select>
        <script>
            $('select[name="is_check"]').find('option[value="{:I(\'request.is_check\')}"]').prop('selected',true);
        </script>

        <input type="submit" class="btn btn-primary" value="搜索"/>
        <a class="btn" href="{:U('afterloan/audit_list')}">清空</a>

        <button class="btn btn-success js-ajax-submit" type="button" id='add_bate' data-action="{:U('afterloan/audit')}" onclick='audit()'>核准</button>

        <span style="float: right;">
            <button class="btn btn-danger js-ajax-submit" type="button" id='del' data-action="{:U('afterloan/del')}" onclick='del_a();'>删除</button>
            <button class="btn btn-danger js-ajax-submit" type="button" id='del_bate' data-action="{:U('afterloan/force_del')}" onclick='force_del();'>强制删除</button>
        </span>

    </form>
    <form method="post" class="js-ajax-form">
        <php>$model = new \User\Model\ReportCurrentOrders();</php>
        <table class="table table-hover table-bordered" id='tab_check'>
            <thead>
            <tr>
                <th style='min-width: 50px;' align="center"><input type="checkbox" id="for_all" />&nbsp;全选</th>
                <th>订单号</th>
                <th>登记日期</th>
                <th>登记人</th>
                <th>用户</th>
                <th>手机</th>
                <th>收款登记金额</th>
                <th>平台</th>
                <th>是否解套</th>
                <th>解套平台</th>
                <th>解套金额</th>
                <th>是否续期</th>
                <th>续期金额</th>
                <th>用户状态</th>
                <th>是否核对</th>
                <th>核对人</th>
                <th>核对时间</th>
            </tr>
            </thead>
            <tbody>
            <foreach name="list" item="vo">
                <tr>
                    <td><input type='checkbox' name='id[]' value='{$vo.id}'/></td>
                    <td>{$orders[$vo['oid']]}</td>
                    <td>{$vo.operation_date}</td>
                    <td>{$admins[$vo['principal']]}</td>
                    <td>{$users[$vo['user_id']]['name']}</td>
                    <td>{$users[$vo['user_id']]['mobile']}</td>
                    <td style="padding: 0;border-top: 0;">
                        <ul class="list-group" style="border: 0;padding: 0;margin: 0;">
                            <li class="list-group-item">
                                <span class="badge">{$vo.total_system_amount}</span>
                                系统
                            </li>
                            <li class="list-group-item">
                                <span class="badge">{$vo.total_wechat_amount}</span>
                                <span style="color:green">微信({$admins[$vo['wechat_rev_admin_id']]})</span>
                            </li>
                            <li class="list-group-item">
                                <span class="badge">{$vo.total_alipay_amount}</span>
                                <span style="color:blue">支付宝({$admins[$vo['alipay_rev_admin_id']]})</span>
                            </li>
                            <li class="list-group-item">
                                <span class="badge">{$vo.total_bank_amount}</span>
                                <span style="color:#ff8216">银行转账(上官志勇)</span>
                            </li>
                            <li class="list-group-item">
                                <span class="badge">{$vo.total_rev_amount}</span>
                                <span style="color:darkred">小计：</span>
                            </li>
                        </ul>
                    </td>
                    <td>
                        <php>echo \User\Model\LoanOperationLogModel::getPlatformText($vo['platform']);</php>
                    </td>
                    <td>
                        <php>echo \User\Model\LoanOperationLogModel::getIsReliefText($vo['is_relief']);</php>
                    </td>
                    <td>{$vo.relief_platform_txt}</td>
                    <td>{$vo.relief_amount}</td>
                    <td>
                        <php>echo \User\Model\LoanOperationLogModel::getIsRenewalText($vo['is_renewal']);</php>
                    </td>
                    <td>
                        {$vo['renewal_amount']}
                    </td>
                    <td>
                        <php>echo \User\Model\LoanOperationLogModel::getUserStatusText($vo['user_status']);</php>
                    </td>
                    <td>
                        <php>echo \User\Model\LoanOperationLogModel::getIsCheckText($vo['is_check']);</php>
                    </td>
                    <td>{$admins[$vo['check_admin_id']]}</td>
                    <td>{$vo.check_time}</td>
                </tr>
            </foreach>
            </tbody>
        </table>
        <div class="pagination">{$page}</div>
    </form>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script>
    function audit() {
        var btn = $('button.js-ajax-submit').eq(0);
        var form = $('form.js-ajax-form');
        var obj = document.getElementsByName('id[]');
        var s = 0;
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked) s += 1;
        }
        if (parseInt(s) === 0) {
            return alert('请选择至少一条记录进行核准');
        }
        form.ajaxSubmit({
            url: btn.data('action'),
            //按钮上是否自定义提交地址(多按钮情况)
            dataType: 'json',
            beforeSubmit: function (arr, $form, options) {
                var tx = '核准';
                //按钮文案、状态修改
                btn.text(tx + '中...').attr('disabled', true).addClass('disabled');
            },
            success: function (data, statusText, xhr, $form) {
                //按钮文案、状态修改
                btn.removeClass('disabled').parent().find('span').remove();
                if (data.state === 'success') {
                    $('<span class="tips_success">' + data.info + '</span>').appendTo(btn.parent()).fadeIn('slow').delay(1000).fadeOut(function () {
                        if (data.referer) {
                            //返回带跳转地址
                            if (window.parent.art) {
                                //iframe弹出页
                                window.parent.location.href = data.referer;
                            } else {
                                window.location.href = data.referer;
                            }
                        } else {
                            if (window.parent.art) {
                                //reloadPage(window.parent);
                                window.location.reload();
                            } else {
                                //刷新当前页
                                reloadPage(window);
                            }
                        }
                    });
                } else if (data.state === 'fail') {
                    $('<span class="tips_error">' + data.info + '</span>').appendTo(btn.parent()).fadeIn('fast');
                    btn.text('核准').removeProp('disabled').removeClass('disabled');
                }
            }
        });
    }

    function del_a() {
        var btn = $('button.js-ajax-submit').eq(1);
        var obj = document.getElementsByName('id[]');
        var s = 0;var ids='';
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked){
                s += 1;
                ids += ($(obj[i]).val()+',');
            }
        }
        if (parseInt(s) === 0) {
            return alert('请选择至少一条记录删除');
        }
        Wind.use('artDialog', function () {
            art.dialog({
                title: false,
                icon: 'question',
                content: '确认删除吗？',
                follow: document.getElementById('del'),
                close: function () {
                    return true;
                },
                ok: function () {
                    $.ajax({
                        url:btn.data('action'),
                        type:'post',
                        dataType:'json',
                        data:{id:ids},
                        success:function(map){
                            if (map.state == 'success') {
                                art.dialog({
                                    content: map.info,
                                    icon: 'success',
                                    ok: function () {
                                        this.title(map.info);
                                        return true;
                                    }
                                });
                                window.location.reload();
                            } else if (map.state == 'fail') {
                                art.dialog({
                                    content: map.info,
                                    icon: 'warning',
                                    ok: function () {
                                        this.title(map.info);
                                        return true;
                                    }
                                });
                            }
                        }

                    });
                },
                cancelVal: '关闭',
                cancel: true
            });
        });
    }

    function force_del() {
        var btn = $('button.js-ajax-submit').eq(2);
        var obj = document.getElementsByName('id[]');
        var s = 0;var ids='';
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked){
                s += 1;
                ids += ($(obj[i]).val()+',');
            }
        }
        if (parseInt(s) === 0) {
            return alert('请选择至少一条记录删除');
        }
        Wind.use('artDialog', function () {
            art.dialog({
                title: false,
                icon: 'question',
                content: '确认删除吗？',
                follow: document.getElementById('del'),
                close: function () {
                    return true;
                },
                ok: function () {
                    $.ajax({
                        url:btn.data('action'),
                        type:'post',
                        dataType:'json',
                        data:{id:ids},
                        success:function(map){
                            if (map.state == 'success') {
                                art.dialog({
                                    content: map.info,
                                    icon: 'success',
                                    ok: function () {
                                        this.title(map.info);
                                        return true;
                                    }
                                });
                                window.location.reload();
                            } else if (map.state == 'fail') {
                                art.dialog({
                                    content: map.info,
                                    icon: 'warning',
                                    ok: function () {
                                        this.title(map.info);
                                        return true;
                                    }
                                });
                            }
                        }

                    });
                },
                cancelVal: '关闭',
                cancel: true
            });
        });
    }

    $(function(){
        $('#for_all').click(function(){
            $('input[name="id[]"]').click();
        });
    });

</script>
</body></html>